/**
 * Created by sanni on 2018/5/13.
 */
import axios from 'axios'

// 创建axios实例
// axios.defaults.headers.common['Authorization'] = "Basic ZG9iZXN0OmRiMTIzNDU2";
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

const service = axios.create({
  baseURL: 'http://www.baozhishun.com/chaohu/ChaoHu', // api的base_url
  params:'',
  method: 'get', // default
  headers: {'Authorization': 'Basic ZG9iZXN0OmRiMTIzNDU2'},
  timeout: 50000 // 请求超时时间
})
function paramJson(obj){
  let str='';
  for(let a=0;a<obj.length;a++){
    str+=obj[a].key+'='+obj[a].val;
    if(a<obj.length-1){
      str+='&';
    }
  }
  return str;
}

export function ajaxGet1(obj) {
  let str=paramJson(obj);

  return service({
    url:`/GetChinfo?${str}`
  })
}

export function ajaxGet2(obj) {
  let str=paramJson(obj);

  return service({
    url: `/GetQikan?${str}`
  })
}

export function GetRequest(param){
  var url = window.location.href; //获取url中"?"符后的字串
  var string = '',strs=[];
  if(url.indexOf("?") != -1) {
    var str = url.split('?')[1];
    strs = str.split("&");
    for(var i = 0; i < strs.length; i++) {
      if(param == strs[i].split("=")[0]) {
        string = strs[i].split("=")[1];
      }
    }
  }
  return decodeURIComponent(string);
}
